package com.mundus.engine.assets;

/***
 * Console log functionality
 * @author Johannes du Randt
 *
 */
public class Log {
	public enum LogType
	{
		INFO,
		WARNING,
		ERROR,
		DEBUG,
		NONE
	}	
	
	private static LogType[] _logFilter;
	
	/**
	 * Prints current date and time to log
	 */
	public static void printCurrentDate(){
		System.out.println(DateTime.getCurrentDateTime().getTime());
	}
	
	public static void applyLogFilter(LogType... logTypes){
		_logFilter = logTypes;
	}
	
	
	private static boolean filterMessage(LogType type){
		boolean filterValue = false;
		for(LogType fType : _logFilter)
			if (fType == type){
				filterValue = true;
				break;
			}
		
		return filterValue;
	}
	
	public static LogType info(String message){
		if(!filterMessage(LogType.INFO)) System.out.println(String.format("%s INFO: %s", DateTime.getCurrentDateTime().getTime(), message));
		return LogType.INFO;
	}
	
	public static LogType warning(String message){
		if(!filterMessage(LogType.WARNING)) System.out.println(String.format("%s WARNING: %s", DateTime.getCurrentDateTime().getTime(), message));
		return LogType.WARNING;
	}
	
	public static LogType debug(String message){
		if(!filterMessage(LogType.DEBUG)) System.out.println(String.format("%s DEBUG: %s", DateTime.getCurrentDateTime().getTime(), message));
		return LogType.DEBUG;
	}
	
	public static LogType error(String message){
		if(!filterMessage(LogType.ERROR)) System.out.println(String.format("%s ERROR: %s", DateTime.getCurrentDateTime().getTime(), message));
		System.exit(-1);
		return LogType.ERROR;
	}
	
	public static LogType error(String message, Throwable exception){
		if(!filterMessage(LogType.ERROR)){ System.out.println(String.format("%s ERROR: %s", DateTime.getCurrentDateTime().getTime(), message));
		exception.printStackTrace();}
		System.exit(-1);
		return LogType.ERROR;
	}
	
	public static LogType error(Throwable exception){
		if(!filterMessage(LogType.ERROR)){ System.out.println(DateTime.getCurrentDateTime().getTime());
		exception.printStackTrace();}
		System.exit(-1);
		return LogType.ERROR;
	}
}
